package com.qinsoft.frame.utils;

import java.io.InputStream;
import java.util.Properties;

import com.qinsoft.frame.messages.WriteMessage;

/**
 * description  获取配置文件中的数据
 */ 
public class QinConfig { 
	
	private Properties props = null;
 
	private static QinConfig tbconfig;
	private static QinConfig wbconfig;
	private QinConfig(String type)
	{
		//配置文件对象不存在时创建一个新的配置文件对象
		if(props==null)
		{
			try {
				props=new Properties();
				InputStream filePath = null;
				if(type.equals("taobao")){
					filePath = this.getClass().getResourceAsStream("/tbconfig.properties");
				}
				if(type.equals("sina")){
					filePath = this.getClass().getResourceAsStream("/wbconfig.properties");
				}
				props.load(filePath); 
			} catch (Exception e) {
				WriteMessage.WriteErrorLog(this.getClass().toString()+"TaobaoConfig()", e);
			}
			
		}
	}
	
	/**
	 * 获取配置文件对象
	 */
	public static QinConfig getInstance(String type)
	{
		if(type.equals("taobao")){
			if(tbconfig==null)
			{
				tbconfig = new QinConfig(type);
			}
			return tbconfig;
		}
		if(type.equals("sina")){
			if(wbconfig==null)
			{
				wbconfig = new QinConfig(type);
			}
			return wbconfig;
		}
		return null;
	}
	/**
	 * 获取相应的配置节点信息
	 */
	public String getValue(String key){
		return props.getProperty(key).trim();
	}
}
